﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace NopSolutions.NopCommerce.Web.Modules
{
  public partial class OrderTracking : BaseNopFrontendUserControl
  {
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
      if ((!string.IsNullOrEmpty(tbEmail.Text)) && (!string.IsNullOrEmpty(tbOrderNumber.Text)))
        if ((tbEmail.Text != "E-mail") && (tbEmail.Text != "Номер заказа"))
        {
          Response.Redirect(string.Format("~/ordertracking.aspx?email={0}&ordernumber={1}", HttpUtility.UrlEncode(tbEmail.Text), HttpUtility.UrlEncode(tbOrderNumber.Text)));
        }
    }

    protected override void OnPreRender(EventArgs e)
    {
      tbEmail.Attributes.Add("onfocus", string.Format("if(this.value=='{0}')this.value=''", "E-mail"));
      tbEmail.Attributes.Add("onblur", string.Format("if(this.value=='')this.value='{0}'", "E-mail"));
      tbOrderNumber.Attributes.Add("onfocus", string.Format("if(this.value=='{0}')this.value=''", "Номер заказа"));
      tbOrderNumber.Attributes.Add("onblur", string.Format("if(this.value=='')this.value='{0}'", "Номер заказа"));
      
      tbEmail.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('" + btnSearch.ClientID + "').click();return false;}} else {return true}; ");
      tbOrderNumber.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('" + btnSearch.ClientID + "').click();return false;}} else {return true}; ");
      base.OnPreRender(e);
    }
  }
}